import {ElLoading, ElMessageBox, ElNotification} from "element-plus";

let loading;
export const alert = (message, options = {}) => {
    return ElMessageBox.alert(message, options.title || '提示', {
        confirmButtonText: '确定',
        callback: (action) => {
            if (options.callback) {
                options.callback(action);
            }
        }
    })
};

export const confirm = (message, options = {}) => {
    return ElMessageBox.confirm(
        message,
        options.title || '警告',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }
    )
};

export const notify = (message, options = {type: 'success'}) => {
    ElNotification({
        message: message,
        position: 'top-right',
        type: options.type || 'info',
        title: options.title || '提示',
        onClose: () => {
            if (options.onClose) {
                options.onClose();
            }
        },
        onClick: () => {
            if (options.onClick) {
                options.onClick();
            }
        }
    })
};

export const open = () => {
    loading = ElLoading.service({
        lock: true,
        text: '玩命加载中......',
        background: 'rgba(0, 0, 0, 0.7)',
    });
};


export const close = () => {
    loading.close();
};
